package lambda;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.PriorityQueue;

//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}


//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}

//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}


//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}

public class Test {
    public static void main5(String[] args) {
        HashMap<Integer,String> map = new HashMap<>();
        map.put(1,"hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");

        map.forEach((key,val)->{
            System.out.println("key:"+key +" val: "+val);
        });
    }

    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("max");
        list.add("bit");
        list.add("hello");
        list.add("lambda");

        list.forEach(s-> System.out.println(s));

        System.out.println("=====================");
        list.sort((o1,o2)->o1.compareTo(o2));

        list.forEach(s-> System.out.println(s));
    }

    public static void main3(String[] args) {
        NoParameterReturn noParameterReturn = ()->10;
        System.out.println(noParameterReturn.test());

        OneParameterReturn oneParameterReturn = a-> a+10;
        System.out.println(oneParameterReturn.test(9));

        MoreParameterReturn moreParameterReturn = (a,b)->a*b;
        System.out.println(moreParameterReturn.test(1,2));

    }

    public static void main2(String[] args) {
        int x = 10;
        MoreParameterNoReturn moreParameterNoReturn = (a,b)-> {
            System.out.println(x);
            System.out.println(a+b);
        };

        moreParameterNoReturn.test(1,2);
    }

    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("test......");
            }
        };

        noParameterNoReturn.test();

        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>((x,y)-> x-y);
    }

}
